export const storage = {
  /**
   * 存储数据在本地
   */
  setItem(key: string, value: unknown) {
    if (typeof value === 'object') {
      value = JSON.stringify(value)
    }
    window.localStorage.setItem(key, String(value))
  },
  /**
   * 获取本地存储的数据
   */
  getItem(key: string) {
    const data = window.localStorage.getItem(key)
    if (data === null) return data
    try {
      return JSON.parse(data)
    } catch (e) {
      return data
    }
  },
  // 删除数据
  removeItem(key: string) {
    window.localStorage.removeItem(key)
  }
}
